<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Set实现交并差</title>
</head>
<body>
    <script>
        let a = new Set([1,2,3,4,5]);
        let b = new Set([3,4,5,6,7]);

        // 并集
        console.log(new Set([...a,...b]));

        // 交集
        console.log(
            new Set(
                [...a].filter(function (value) {
                    return b.has(value);
                })
            )
        )

        //差集
        console.log(
            new Set(
                [...a].filter(function (value) {
                    return !b.has(value);
                })
            )
        )
        
    </script>
</body>
</html>